package cn.lqs.crm.web.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

//对swagger进行配置
@Configuration  //相当于自己去创建一个applicationContext.xml
@EnableWebMvc  //开启springmvc和swagger的配置
@EnableSwagger2
//扫描个包下面controller来生成接口描述  扫描包可以不用管它，因为下面还会扫描
//@ComponentScan(basePackages="cn.lqs.crm.web.controller")
public class SwaggerConfig {

    //Bean 就相当于自己再配置文件里写<Bean />这个东西，把这个类注入到spring容器里
    @Bean
    public Docket api(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(this.apiInfo())//配置信息
                .select()  //得到builder对象
                .apis(RequestHandlerSelectors.basePackage("cn.lqs.crm.web.controller")) //扫面我们的controller
                .paths(PathSelectors.any())  //查找包下面的所有路径
                .build();
    }
    

    private ApiInfo apiInfo(){
         @SuppressWarnings("deprecation")
        ApiInfo info=new ApiInfo(
                 "lqs20191107crud测试",
                 "一个完成crud",
                 "v1",
                 "http://www.itsource.cn",
                 "lqs",
                 "apache",
                 "http://www.itsource.cn");
         return info;
    }
}